/*初始化数据表格*/
function initTable() {
    var url=getBasePath()+'/mdm/questionnaire/getListData.json';
    var tableId="table_data";
    $("#"+tableId).dataTable().fnDestroy();
    json = {};
    json.showLineNuber = false;
    json.id = tableId;
    json.pagesize=10;
    json.url = url ;
    json.param = [
        {"name": "qnId", "value": $.trim($("#qnId").val())},
        {"name": "qnCode", "value": $.trim($("#qnCode").val())},
        {"name": "qnName", "value": $.trim($("#qnName").val())},
        {"name": "qnDescription", "value": $.trim($("#qnDescription").val())},
        {"name": "validTime", "value": $.trim($("#validTime").val())},
        {"name": "tillTime", "value": $.trim($("#tillTime").val())},
        {"name": "ifRelease", "value": $.trim($("#ifRelease").val())},
        {"name": "releaseTime", "value": $.trim($("#releaseTime").val())},
        {"name": "deleteMark", "value": $.trim($("#deleteMark").val())},
        {"name": "createUser", "value": $.trim($("#createUser").val())},
        {"name": "createTime", "value": $.trim($("#createTime").val())},
        {"name": "updateUser", "value": $.trim($("#updateUser").val())},
        {"name": "updateTime", "value": $.trim($("#updateTime").val())},
    ];
    json.columns = [
        {
            "mData": "questionnaireCode", "sWidth": "15%", "sClass": "text-center",
            "mRender": function (data, type, row) {
                if (data) {
					var detailStr="<a class='icondatatable' vb='详情' href=\"#\" onclick='toDetailPage(\""+data+"\");'><i class=\"icon-detail\"></i></a>";
                    var editStr="<a class='icondatatable' vb='修改' href=\"#\" onclick='toEditQuestionnaire(\""+data+"\");'><i class=\"icon-edit\"></i></a>";
                    var delStr="<a class='icondatatable' vb='删除' href=\"#\"  onclick='deleteQuestionnaire(\""+data+"\");'><i class=\"icon-bin\"></i></a>";

                    return detailStr+editStr+delStr;
                }
            }
        },
        {"mData": "qnId", "sClass": "text-center"},
        {"mData": "qnCode", "sClass": "text-center"},
        {"mData": "qnName", "sClass": "text-center"},
        {"mData": "qnDescription", "sClass": "text-center"},
        {"mData": "validTime", "sClass": "text-center"},
        {"mData": "tillTime", "sClass": "text-center"},
        {"mData": "ifRelease", "sClass": "text-center"},
        {"mData": "releaseTime", "sClass": "text-center"},
        {"mData": "deleteMark", "sClass": "text-center"},
        {"mData": "createUser", "sClass": "text-center"},
        {"mData": "createTime", "sClass": "text-center"},
        {"mData": "updateUser", "sClass": "text-center"},
        {"mData": "updateTime", "sClass": "text-center"},
    ];
    var oTable1 = TableManaged(json).init();
}
/*查询数据*/
function doQuery(){
    initTable();
}


/*重置查询条件*/
function resetQueryForm(){
	$("#qnId").val('');
	$("#qnCode").val('');
	$("#qnName").val('');
	$("#qnDescription").val('');
	$("#validTime").val('');
	$("#tillTime").val('');
	$("#ifRelease").val('');
	$("#releaseTime").val('');
	$("#deleteMark").val('');
	$("#createUser").val('');
	$("#createTime").val('');
	$("#updateUser").val('');
	$("#updateTime").val('');
}

/*删除数据*/
function deleteQuestionnaire(questionnaireCode){
    var _url=getBasePath()+'/mdm/questionnaire/delete.json';
    $.Confirm('你确定要删除这条记录吗？','',function(){
        var questionnaire={};
        questionnaire.questionnaireCode=questionnaireCode;
        $.ajax({
            url:_url,
            type:'POST',
            dataType:'json',
            contentType:'application/json',
            data:JSON.stringify(questionnaire),
            success:function(data){
                if(data.status==200){
                    $.Success('删除成功',doQuery);
                }else{
                    var msg = data.message || "删除调查问卷数据发生错误";
                    $.Error(msg,'',null);
                }
            }
        });
    });

}

/*跳转编辑数据页面*/
function toEditQuestionnaire(questionnaireCode){
    var _url=getBasePath()+'/mdm/questionnaire/toEdit.htm?questionnaireCode='+questionnaireCode;
    location.href=_url;
}

/*编辑数据*/
function editQuestionnaire(){
    $validator =$("#questionnaire_edit_form").validator('isFormValid');
    if(!$validator){
        return;
    }
    var _url=getBasePath()+'/mdm/questionnaire/edit.json';
    var questionnaire={};
	questionnaire.qnId=$("#qnId").val();
	questionnaire.qnCode=$("#qnCode").val();
	questionnaire.qnName=$("#qnName").val();
	questionnaire.qnDescription=$("#qnDescription").val();
	questionnaire.validTime=$("#validTime").val();
	questionnaire.tillTime=$("#tillTime").val();
	questionnaire.ifRelease=$("#ifRelease").val();
	questionnaire.releaseTime=$("#releaseTime").val();
	questionnaire.deleteMark=$("#deleteMark").val();
	questionnaire.createUser=$("#createUser").val();
	questionnaire.createTime=$("#createTime").val();
	questionnaire.updateUser=$("#updateUser").val();
	questionnaire.updateTime=$("#updateTime").val();

    $.ajax({
        url:_url,
        type:'POST',
        dataType:'json',
        contentType:'application/json',
        data:JSON.stringify(questionnaire),
        success:function(data){
            if(data.status==200){
                $.Success('该记录已提交成功!',gotoListPage);
            }else{
                var msg = data.message || "编辑调查问卷数据发生错误";
                $.Error(msg,'',null);
            }

        },
        error:function(data){
            JSON.stringify(data);
        }
    });
}

/* 跳转明细页面*/
function toDetailPage(code){
    var _url=getBasePath()+'/mdm/questionnaire/detail.htm?questionnaireCode='+code;
    location.href=_url;
}
/*跳转新增数据页面*/
function toAddQuestionnaire(){
    var _url=getBasePath()+'/mdm/questionnaire/toAdd.htm';
    location.href=_url;
}

/*新增数据*/
function saveQuestionnaire(){
    $validator =$("#questionnaire_add_form").validator('isFormValid');
    if(!$validator){
        return;
    }
    var _url=getBasePath()+'/mdm/questionnaire/add.json';
    var questionnaire={};
	questionnaire.qnId=$("#qnId").val();
	questionnaire.qnCode=$("#qnCode").val();
	questionnaire.qnName=$("#qnName").val();
	questionnaire.qnDescription=$("#qnDescription").val();
	questionnaire.validTime=$("#validTime").val();
	questionnaire.tillTime=$("#tillTime").val();
	questionnaire.ifRelease=$("#ifRelease").val();
	questionnaire.releaseTime=$("#releaseTime").val();
	questionnaire.deleteMark=$("#deleteMark").val();
	questionnaire.createUser=$("#createUser").val();
	questionnaire.createTime=$("#createTime").val();
	questionnaire.updateUser=$("#updateUser").val();
	questionnaire.updateTime=$("#updateTime").val();
    
    $.ajax({
        url:_url,
        type:'POST',
        dataType:'json',
        contentType:'application/json',
        data:JSON.stringify(questionnaire),
        success:function(data){
            if(data.status==200){
                $.Success('该记录已提交成功!',gotoListPage);
            }else{
                var msg = data.message || "新增调查问卷数据发生错误";
                $.Error(msg,'',null);
            }
        }
    });
}

/*跳转数据列表页面*/
function gotoListPage(){
    location.href=getBasePath()+'/mdm/questionnaire/list.htm';
}





